package com.ruoyi.project.video.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.video.domain.Video;
import com.ruoyi.project.video.service.IVideoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 视频信息Controller
 * 
 * @author guozy
 * @date 2023-03-13
 */
@Controller
@RequestMapping("/videoManage/video")
public class VideoController extends BaseController
{
    private String prefix = "videoManage/video";

    @Autowired
    private IVideoService videoService;

    @RequiresPermissions("videoManage:video:view")
    @GetMapping()
    public String video()
    {
        return prefix + "/video";
    }

    /**
     * 查询视频信息列表
     */
    @RequiresPermissions("videoManage:video:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Video video)
    {
        startPage();
        List<Video> list = videoService.selectVideoList(video);
        return getDataTable(list);
    }

    /**
     * 导出视频信息列表
     */
    @RequiresPermissions("videoManage:video:export")
    @Log(title = "视频信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Video video)
    {
        List<Video> list = videoService.selectVideoList(video);
        ExcelUtil<Video> util = new ExcelUtil<Video>(Video.class);
        return util.exportExcel(list, "视频信息数据");
    }

    /**
     * 新增视频信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存视频信息
     */
    @RequiresPermissions("videoManage:video:add")
    @Log(title = "视频信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Video video)
    {
        return toAjax(videoService.insertVideo(video));
    }

    /**
     * 修改视频信息
     */
    @RequiresPermissions("videoManage:video:edit")
    @GetMapping("/edit/{title}")
    public String edit(@PathVariable("title") String title, ModelMap mmap)
    {
        Video video = videoService.selectVideoByTitle(title);
        mmap.put("video", video);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频信息
     */
    @RequiresPermissions("videoManage:video:edit")
    @Log(title = "视频信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Video video)
    {
        return toAjax(videoService.updateVideo(video));
    }

    /**
     * 删除视频信息
     */
    @RequiresPermissions("videoManage:video:remove")
    @Log(title = "视频信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(videoService.deleteVideoByTitles(ids));
    }
}
